// Copyright (C) 1953-2022 NUDT
// Verilog module name - table_lookup_pipeline
// Version: V4.0.0.20220524
// Created:
//         by - fenglin 
////////////////////////////////////////////////////////////////////////////
// Description:
//         lookup dmac forward table.
///////////////////////////////////////////////////////////////////////////


module table_lookup_pipeline
(
        i_clk                               , 
        i_rst_n                             ,
        
        i_cyclestart                       ,
        iv_inject_period                    ,
        
        iv_md                               ,
        i_md_wr                             ,
                
        iv_dmacram_addr                     ,
        iv_dmacram_wdata                    ,
        i_dmacram_wr                        ,
        ov_dmacram_rdata                    ,
        i_dmacram_rd                        ,

        iv_ipram_addr_cpe2ram               ,
        iv_ipram_wdata_cpe2ram              ,
        i_ipram_wr_cpe2ram                  ,
        i_ipram_rd_cpe2ram                  ,
        ov_ipram_rdata_ram2cpe              ,

        iv_droute_portbm_cpe2tlp               ,
        iv_sroute_portbm_cpe2tlp               ,
        i_unknown_multicast_forwardmode_cpe2tlp,
        
        iv_flowidram_addr                   ,
        iv_flowidram_wdata                  ,
		i_flowidram_wr                      ,
		ov_flowidram_rdata                  ,
        i_flowidram_rd                      ,
		
        o_tsmp_lookup_table_key_wr          ,
        ov_tsmp_lookup_table_key            ,
        iv_tsmp_lookup_table_outport        ,
        i_tsmp_lookup_table_outport_wr      ,
        
        ov_md                               ,
        o_md_wr                             ,

        iv_broadcast_storm_prevent_outport           ,

        i_hit_cnt_clr                       ,  
        
        ov_entry0_hit_cnt                   ,
        ov_entry1_hit_cnt                   ,
        ov_entry2_hit_cnt                   ,
        ov_entry3_hit_cnt                   ,
        ov_entry4_hit_cnt                   ,
        ov_entry5_hit_cnt                   ,
        ov_entry6_hit_cnt                   ,
        ov_entry7_hit_cnt                   , 
        ov_entry8_hit_cnt ,
        ov_entry9_hit_cnt ,
        ov_entry10_hit_cnt,
        ov_entry11_hit_cnt,
        ov_entry12_hit_cnt,
        ov_entry13_hit_cnt,
        ov_entry14_hit_cnt,
        ov_entry15_hit_cnt,
        ov_entry16_hit_cnt,
        ov_entry17_hit_cnt,
        ov_entry18_hit_cnt,
        ov_entry19_hit_cnt,
        ov_entry20_hit_cnt,
        ov_entry21_hit_cnt,
        ov_entry22_hit_cnt,
        ov_entry23_hit_cnt,
        ov_entry24_hit_cnt,
        ov_entry25_hit_cnt,
        ov_entry26_hit_cnt,
        ov_entry27_hit_cnt,
        ov_entry28_hit_cnt,
        ov_entry29_hit_cnt,
        ov_entry30_hit_cnt,
        ov_entry31_hit_cnt,
        ov_entry32_hit_cnt,
        ov_entry33_hit_cnt,
        ov_entry34_hit_cnt,
        ov_entry35_hit_cnt,
        ov_entry36_hit_cnt,
        ov_entry37_hit_cnt,
        ov_entry38_hit_cnt,
        ov_entry39_hit_cnt,
        ov_entry40_hit_cnt,
        ov_entry41_hit_cnt,
        ov_entry42_hit_cnt,
        ov_entry43_hit_cnt,
        ov_entry44_hit_cnt,
        ov_entry45_hit_cnt,
        ov_entry46_hit_cnt,
        ov_entry47_hit_cnt,
        ov_entry48_hit_cnt,
        ov_entry49_hit_cnt,
        ov_entry50_hit_cnt,
        ov_entry51_hit_cnt,
        ov_entry52_hit_cnt,
        ov_entry53_hit_cnt,
        ov_entry54_hit_cnt,
        ov_entry55_hit_cnt,
        ov_entry56_hit_cnt,
        ov_entry57_hit_cnt,
        ov_entry58_hit_cnt,
        ov_entry59_hit_cnt,
        ov_entry60_hit_cnt,
        ov_entry61_hit_cnt,
        ov_entry62_hit_cnt,
        ov_entry63_hit_cnt        
);
// I/O
// clk & rst  
input                   i_clk  ;
input                   i_rst_n;

input                   i_cyclestart;
input       [10:0]      iv_inject_period;
//                      
input       [299:0]     iv_md  ;
input                   i_md_wr;
//read ram              
output                  o_tsmp_lookup_table_key_wr    ;
output      [47:0]      ov_tsmp_lookup_table_key      ;
input       [32:0]      iv_tsmp_lookup_table_outport  ;
input                   i_tsmp_lookup_table_outport_wr;

input       [5:0]       iv_dmacram_addr     ;
input       [81:0]      iv_dmacram_wdata    ;
input                   i_dmacram_wr        ;
output      [81:0]      ov_dmacram_rdata    ;
input                   i_dmacram_rd        ;

input   wire    [2:0]       iv_ipram_addr_cpe2ram                   ;
input   wire    [64:0]      iv_ipram_wdata_cpe2ram                  ;
input   wire                i_ipram_wr_cpe2ram                      ;
input   wire                i_ipram_rd_cpe2ram                      ;
output  wire    [64:0]      ov_ipram_rdata_ram2cpe                  ;

input   wire    [31:0]      iv_droute_portbm_cpe2tlp                ;
input   wire    [31:0]      iv_sroute_portbm_cpe2tlp                ;
input   wire                i_unknown_multicast_forwardmode_cpe2tlp ;


input       [13:0]      iv_flowidram_addr   ;
input       [73:0]      iv_flowidram_wdata  ;
input                   i_flowidram_wr      ;
output      [73:0]      ov_flowidram_rdata  ;
input                   i_flowidram_rd      ;

output      [299:0]     ov_md               ;
output                  o_md_wr             ;

input       [32:0]      iv_broadcast_storm_prevent_outport;

input                   i_hit_cnt_clr            ;
                    
output      [15:0]      ov_entry0_hit_cnt ;
output      [15:0]      ov_entry1_hit_cnt ;
output      [15:0]      ov_entry2_hit_cnt ;
output      [15:0]      ov_entry3_hit_cnt ;
output      [15:0]      ov_entry4_hit_cnt ;
output      [15:0]      ov_entry5_hit_cnt ;
output      [15:0]      ov_entry6_hit_cnt ;
output      [15:0]      ov_entry7_hit_cnt ;
output     [15:0]  ov_entry8_hit_cnt ;
output     [15:0]  ov_entry9_hit_cnt ;
output     [15:0]  ov_entry10_hit_cnt;
output     [15:0]  ov_entry11_hit_cnt;
output     [15:0]  ov_entry12_hit_cnt;
output     [15:0]  ov_entry13_hit_cnt;
output     [15:0]  ov_entry14_hit_cnt;
output     [15:0]  ov_entry15_hit_cnt;
output     [15:0]  ov_entry16_hit_cnt;
output     [15:0]  ov_entry17_hit_cnt;
output     [15:0]  ov_entry18_hit_cnt;
output     [15:0]  ov_entry19_hit_cnt;
output     [15:0]  ov_entry20_hit_cnt;
output     [15:0]  ov_entry21_hit_cnt;
output     [15:0]  ov_entry22_hit_cnt;
output     [15:0]  ov_entry23_hit_cnt;
output     [15:0]  ov_entry24_hit_cnt;
output     [15:0]  ov_entry25_hit_cnt;
output     [15:0]  ov_entry26_hit_cnt;
output     [15:0]  ov_entry27_hit_cnt;
output     [15:0]  ov_entry28_hit_cnt;
output     [15:0]  ov_entry29_hit_cnt;
output     [15:0]  ov_entry30_hit_cnt;
output     [15:0]  ov_entry31_hit_cnt;
output     [15:0]  ov_entry32_hit_cnt;
output     [15:0]  ov_entry33_hit_cnt;
output     [15:0]  ov_entry34_hit_cnt;
output     [15:0]  ov_entry35_hit_cnt;
output     [15:0]  ov_entry36_hit_cnt;
output     [15:0]  ov_entry37_hit_cnt;
output     [15:0]  ov_entry38_hit_cnt;
output     [15:0]  ov_entry39_hit_cnt;
output     [15:0]  ov_entry40_hit_cnt;
output     [15:0]  ov_entry41_hit_cnt;
output     [15:0]  ov_entry42_hit_cnt;
output     [15:0]  ov_entry43_hit_cnt;
output     [15:0]  ov_entry44_hit_cnt;
output     [15:0]  ov_entry45_hit_cnt;
output     [15:0]  ov_entry46_hit_cnt;
output     [15:0]  ov_entry47_hit_cnt;
output     [15:0]  ov_entry48_hit_cnt;
output     [15:0]  ov_entry49_hit_cnt;
output     [15:0]  ov_entry50_hit_cnt;
output     [15:0]  ov_entry51_hit_cnt;
output     [15:0]  ov_entry52_hit_cnt;
output     [15:0]  ov_entry53_hit_cnt;
output     [15:0]  ov_entry54_hit_cnt;
output     [15:0]  ov_entry55_hit_cnt;
output     [15:0]  ov_entry56_hit_cnt;
output     [15:0]  ov_entry57_hit_cnt;
output     [15:0]  ov_entry58_hit_cnt;
output     [15:0]  ov_entry59_hit_cnt;
output     [15:0]  ov_entry60_hit_cnt;
output     [15:0]  ov_entry61_hit_cnt;
output     [15:0]  ov_entry62_hit_cnt;
output     [15:0]  ov_entry63_hit_cnt;

wire        [299:0]     wv_md_fso2epl   ;
wire                    w_md_wr_fso2epl ;

wire        [299:0]     wv_md_epl2mpl   ;
wire                    w_md_wr_epl2mpl ;

wire        [299:0]     wv_md_mpl2tpl   ;
wire                    w_md_wr_mpl2tpl ;

flow_sort flow_sort_inst(
.i_clk                          (i_clk  ),
.i_rst_n                        (i_rst_n),

.iv_broadcast_storm_prevent_outport(iv_broadcast_storm_prevent_outport),
                                
.iv_md                          (iv_md  ),
.i_md_wr                        (i_md_wr),

.ov_md                          (wv_md_fso2epl   ),
.o_md_wr                        (w_md_wr_fso2epl )
);

ethernet_packet_lookup ethernet_packet_lookup_inst(
.i_clk                          (i_clk  ),
.i_rst_n                        (i_rst_n),

.iv_md                          (wv_md_fso2epl   ),
.i_md_wr                        (w_md_wr_fso2epl ),

.iv_dmacram_addr                (iv_dmacram_addr ), 
.iv_dmacram_wdata               (iv_dmacram_wdata),
.i_dmacram_wr                   (i_dmacram_wr    ),
.ov_dmacram_rdata               (ov_dmacram_rdata),
.i_dmacram_rd                   (i_dmacram_rd    ),

.o_tsmp_lookup_table_key_wr     (o_tsmp_lookup_table_key_wr    ), 
.ov_tsmp_lookup_table_key       (ov_tsmp_lookup_table_key      ),
.iv_tsmp_lookup_table_outport   (iv_tsmp_lookup_table_outport  ),
.i_tsmp_lookup_table_outport_wr (i_tsmp_lookup_table_outport_wr),

.ov_md                          (wv_md_epl2mpl            ),
.o_md_wr                        (w_md_wr_epl2mpl          ),

.iv_broadcast_storm_prevent_outport      (iv_broadcast_storm_prevent_outport),

.i_hit_cnt_clr                  (i_hit_cnt_clr            ), 
                                                          
.ov_entry0_hit_cnt              (ov_entry0_hit_cnt        ),
.ov_entry1_hit_cnt              (ov_entry1_hit_cnt        ),
.ov_entry2_hit_cnt              (ov_entry2_hit_cnt        ),
.ov_entry3_hit_cnt              (ov_entry3_hit_cnt        ),
.ov_entry4_hit_cnt              (ov_entry4_hit_cnt        ),
.ov_entry5_hit_cnt              (ov_entry5_hit_cnt        ),
.ov_entry6_hit_cnt              (ov_entry6_hit_cnt        ),
.ov_entry7_hit_cnt              (ov_entry7_hit_cnt        ),
.ov_entry8_hit_cnt              (ov_entry8_hit_cnt ),
.ov_entry9_hit_cnt              (ov_entry9_hit_cnt ),
.ov_entry10_hit_cnt             (ov_entry10_hit_cnt),
.ov_entry11_hit_cnt             (ov_entry11_hit_cnt),
.ov_entry12_hit_cnt             (ov_entry12_hit_cnt),
.ov_entry13_hit_cnt             (ov_entry13_hit_cnt),
.ov_entry14_hit_cnt             (ov_entry14_hit_cnt),
.ov_entry15_hit_cnt             (ov_entry15_hit_cnt),         
.ov_entry16_hit_cnt             (ov_entry16_hit_cnt),
.ov_entry17_hit_cnt             (ov_entry17_hit_cnt),
.ov_entry18_hit_cnt             (ov_entry18_hit_cnt),
.ov_entry19_hit_cnt             (ov_entry19_hit_cnt),
.ov_entry20_hit_cnt             (ov_entry20_hit_cnt),
.ov_entry21_hit_cnt             (ov_entry21_hit_cnt),
.ov_entry22_hit_cnt             (ov_entry22_hit_cnt),
.ov_entry23_hit_cnt             (ov_entry23_hit_cnt),         
.ov_entry24_hit_cnt             (ov_entry24_hit_cnt),
.ov_entry25_hit_cnt             (ov_entry25_hit_cnt),
.ov_entry26_hit_cnt             (ov_entry26_hit_cnt),
.ov_entry27_hit_cnt             (ov_entry27_hit_cnt),
.ov_entry28_hit_cnt             (ov_entry28_hit_cnt),
.ov_entry29_hit_cnt             (ov_entry29_hit_cnt),
.ov_entry30_hit_cnt             (ov_entry30_hit_cnt),
.ov_entry31_hit_cnt             (ov_entry31_hit_cnt),         
.ov_entry32_hit_cnt             (ov_entry32_hit_cnt),
.ov_entry33_hit_cnt             (ov_entry33_hit_cnt),
.ov_entry34_hit_cnt             (ov_entry34_hit_cnt),
.ov_entry35_hit_cnt             (ov_entry35_hit_cnt),
.ov_entry36_hit_cnt             (ov_entry36_hit_cnt),
.ov_entry37_hit_cnt             (ov_entry37_hit_cnt),
.ov_entry38_hit_cnt             (ov_entry38_hit_cnt),
.ov_entry39_hit_cnt             (ov_entry39_hit_cnt),         
.ov_entry40_hit_cnt             (ov_entry40_hit_cnt),
.ov_entry41_hit_cnt             (ov_entry41_hit_cnt),
.ov_entry42_hit_cnt             (ov_entry42_hit_cnt),
.ov_entry43_hit_cnt             (ov_entry43_hit_cnt),
.ov_entry44_hit_cnt             (ov_entry44_hit_cnt),
.ov_entry45_hit_cnt             (ov_entry45_hit_cnt),
.ov_entry46_hit_cnt             (ov_entry46_hit_cnt),
.ov_entry47_hit_cnt             (ov_entry47_hit_cnt),         
.ov_entry48_hit_cnt             (ov_entry48_hit_cnt),
.ov_entry49_hit_cnt             (ov_entry49_hit_cnt),
.ov_entry50_hit_cnt             (ov_entry50_hit_cnt),
.ov_entry51_hit_cnt             (ov_entry51_hit_cnt),
.ov_entry52_hit_cnt             (ov_entry52_hit_cnt),
.ov_entry53_hit_cnt             (ov_entry53_hit_cnt),
.ov_entry54_hit_cnt             (ov_entry54_hit_cnt),
.ov_entry55_hit_cnt             (ov_entry55_hit_cnt),         
.ov_entry56_hit_cnt             (ov_entry56_hit_cnt),
.ov_entry57_hit_cnt             (ov_entry57_hit_cnt),
.ov_entry58_hit_cnt             (ov_entry58_hit_cnt),
.ov_entry59_hit_cnt             (ov_entry59_hit_cnt),
.ov_entry60_hit_cnt             (ov_entry60_hit_cnt),
.ov_entry61_hit_cnt             (ov_entry61_hit_cnt),
.ov_entry62_hit_cnt             (ov_entry62_hit_cnt),
.ov_entry63_hit_cnt             (ov_entry63_hit_cnt)
);
tsn_packet_lookup tsn_packet_lookup_inst(
.i_clk                          (i_clk  ),
.i_rst_n                        (i_rst_n),

.i_cyclestart                  (i_cyclestart),
.iv_inject_period               (iv_inject_period),

.iv_md                          (wv_md_mpl2tpl   ),
.i_md_wr                        (w_md_wr_mpl2tpl ),

.iv_flowidram_addr              (iv_flowidram_addr  ), 
.iv_flowidram_wdata             (iv_flowidram_wdata ),
.i_flowidram_wr                 (i_flowidram_wr     ),
.ov_flowidram_rdata             (ov_flowidram_rdata ),
.i_flowidram_rd                 (i_flowidram_rd     ),

.ov_md                          (ov_md   ),
.o_md_wr                        (o_md_wr )
);


multicast_packet_lookup multicast_packet_lookup_inst(                        
    .i_clk                                   (i_clk  ),
    .i_rst_n                                 (i_rst_n),

    .iv_md_epl2mpl                           (wv_md_epl2mpl  ),
    .i_md_wr_epl2mpl                         (w_md_wr_epl2mpl),

    .iv_ipram_addr_cpe2ram                   (iv_ipram_addr_cpe2ram ),
    .iv_ipram_wdata_cpe2ram                  (iv_ipram_wdata_cpe2ram),
    .i_ipram_wr_cpe2ram                      (i_ipram_wr_cpe2ram    ),
    .i_ipram_rd_cpe2ram                      (i_ipram_rd_cpe2ram    ),
    .ov_ipram_rdata_ram2cpe                  (ov_ipram_rdata_ram2cpe),

    .iv_droute_portbm_cpe2tlp                (iv_droute_portbm_cpe2tlp               ),
    .iv_sroute_portbm_cpe2tlp                (iv_sroute_portbm_cpe2tlp               ),
    .i_unknown_multicast_forwardmode_cpe2tlp (i_unknown_multicast_forwardmode_cpe2tlp),

    .ov_md_mpl2tlp                           (wv_md_mpl2tpl  ),
    .o_md_wr_mpl2tlp                         (w_md_wr_mpl2tpl)
);

endmodule           
